penguin_pca <- penguins %>%
select(body_mass_g, ends_with("_mm")) %>%
drop_na() %>%
scale() %>%
prcomp()
penguin_complete <- penguins %>%
drop_na(body_mass_g, ends_with("_mm"))
autoplot(penguin_pca,
data = penguin_complete,
colour = 'species',
loadings = TRUE,
loadings.label = TRUE) +
theme_minimal()
## Warning: `select_()` is deprecated as of dplyr 0.7.0.
## Please use `select()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
fish_noaa <- read_excel(here("data", "foss_landings.xlsx")) %>%
clean_names() %>%
mutate(across(where(is.character), tolower)) %>%
mutate(nmfs_name = str_sub(nmfs_name, end = -4)) %>%
filter(confidentiality == "public")
Make a customized graph:
fish_plot <- ggplot(data = fish_noaa, aes(x = year, y = pounds)) +
geom_line(aes(color = nmfs_name), show.legend = FALSE) +
theme_minimal()
fish_plot
## Warning: Removed 6 rows containing missing values (geom_path).
ggplotly(fish_plot)
### Use gghighlight to highlight certain series
ggplot(data = fish_noaa, aes(x = year, y = pounds, group = nmfs_name)) +
geom_line() +
theme_minimal() +
gghighlight(max(pounds) > 1e8)
## label_key: nmfs_name
## Warning: Removed 6 rows containing missing values (geom_path).
lubridate(), mutate(), make a graph with months in logical ordermonroe_wt <- read_csv("https://data.bloomington.in.gov/dataset/2c81cfe3-62c2-46ed-8fcf-83c1880301d1/resource/13c8f7aa-af51-4008-80a9-56415c7c931e/download/mwtpdailyelectricitybclear.csv") %>%
clean_names()
## Parsed with column specification:
## cols(
## date = col_character(),
## kWh1 = col_double(),
## kW1 = col_double(),
## kWh2 = col_double(),
## kW2 = col_double(),
## solar_kWh = col_double(),
## total_kWh = col_double(),
## MG = col_double()
## )
monroe_ts <- monroe_wt %>%
mutate(date = mdy(date)) %>%
mutate(record_month = month(date)) %>%
mutate(month_name = month.abb[record_month]) %>%
mutate(month_name = fct_reorder(month_name, record_month))
ggplot(data = monroe_ts, aes(month_name, y = total_k_wh)) +
geom_jitter() +
theme_minimal()
patchworkPatchwork is very cool, there’s all kinds of customizing stuff you can do.
graph_a <- ggplot(data = penguins, aes(x = body_mass_g, y = flipper_length_mm)) +
geom_point()
graph_b <- ggplot(data = penguins, aes(x = species, y = flipper_length_mm)) +
geom_jitter(aes(color = species), show.legend = FALSE)
# Use | to put graphs side by side
# Use / to put graphs one over the other
graph_c <- (graph_a | graph_b)/fish_plot & theme_dark()
graph_c
## Warning: Removed 2 rows containing missing values (geom_point).
## Warning: Removed 2 rows containing missing values (geom_point).
## Warning: Removed 6 rows containing missing values (geom_path).
ggsave(here("fig", "graph_c_az.png"), width = 5, height = 6)
## Warning: Removed 2 rows containing missing values (geom_point).
## Warning: Removed 2 rows containing missing values (geom_point).
## Warning: Removed 6 rows containing missing values (geom_path).